package com.example.springboot.common;

import lombok.Data;

@Data
public class Result {//包装后台数据发送给前端
    public static final String SUCCESS_CODE = "200";
    public static final String ERROR_CODE = "-1";

    private String code;//接口的响应结果
    private Object data;//传输数据
    private String msg;//错误信息

    public static Result success(){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        return result;
    }

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setData(data);
        return result;
    }

    public static Result error(String msg){
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMsg(msg);
        return result;
    }
}
